package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppTaskRecord;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterTaskRecordDao.java
 * @Description 任务记录
 * @createTime 2021年07月26日 11:08:00
 */
@Repository
public class AfterTaskRecordDao extends BaseDao<AppTaskRecord> {

    /**
     * 新增/更新
     * @param appTaskRecord
     */
    public void saveOrUpdate(AppTaskRecord appTaskRecord) {
        if (appTaskRecord!=null && appTaskRecord.getId() != null && appTaskRecord.getId() >0) {
            this.add(appTaskRecord);
        } else {
            appTaskRecord.setId(this.add(appTaskRecord));
        }
    }

    /**
     * 综合查询
     * @param paramap
     * @param splitPageBean
     * @return
     */
    public List<AppTaskRecord> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_task_record where 1=1 ");
        if (StringEx.isNotNull(paramap.get("userId"))) {
            str.append(" and userid = ? ");
            list.add(paramap.get("userId"));
        }
        if (StringEx.isNotNull(paramap.get("nick"))) {
            str.append(" and nick like ");
            str.append(" '%" + paramap.get("nick") + "%'");
        }
        if (!StringEx.isNull(paramap.get("startDate"))) {
            str.append(" and createtime>=? ");
            list.add(paramap.get("startDate"));
        }
        if (!StringEx.isNull(paramap.get("endDate"))) {
            str.append(" and createtime<=? ");
            list.add(paramap.get("endDate"));
        }
        String sql = str.toString();
        return this.queryList(sql,list,AppTaskRecord.class,splitPageBean);
    }


}